<?php

class Login extends S_Controller {

	public function __construct() {
		
		parent::__construct();

		$this->Mdata = $this->loadmodel('mlogin');
		//$this->excel = $this->loadlib('excel');
	}

	public function index() {

		$books = $this->Mdata->getBookName();
	
		echo "<pre>";
		print_r($books);
		echo "</pre>";
	}

	public function output() {

		$excel = $this->loadlib('excel', 'excel');

		//activate worksheet number 1
		$excel->setActiveSheetIndex(0);
		$excel->getActiveSheet()->setTitle('test worksheet');
		$excel->getActiveSheet()->setCellValue('A1', 'This is just some text value');
		$excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(20);
		$excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
		//merge cell A1 until D1
		$excel->getActiveSheet()->mergeCells('A1:D1');
		$excel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

		$filename = 'test' .rand(1, 999) . '.xlsx';
		header('Content-Type: application/vnd.ms-excel');
		header('Content-Disposition: attachment; filename="' . $filename . '"');
		header('Cache-Control: max-age=0');

		//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007'(and adjust the filename extension, also the header mime type)
		$objWriter = PHPExcel_IOFactory::createWriter($excel, 'Excel2007'); 
		$objWriter->save('php://output');
	}


	// another way to export xls
	/*public function export(){

		$list = $this->mhome->users_export_list();
		$data ='<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
	 			<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	 			<html><head><meta http-equiv="Content-type" content="text/html;charset=UTF-8" /></head>';
	    $data.='<body>
	         <div id="Classeur1_16681" align=center x:publishsource="Excel">
	             <table x:str border=0 cellpadding=0 cellspacing=0 width=100% style="border-collapse: collapse">
	                 <tr><td >用户昵称</td><td >手机</td><td >邮箱</td><td >注册时间</td></tr>';
	    foreach ($list as $row) {
	    	 $data.='<tr><td >'.$row['user_nick'].'</td><td >'.$row['user_phone'].'</td><td >'.$row['user_email'].'</td><td >'.$row['created_datetime'].'</td></tr>';
	    }
	    $data.= '</table></div></body></html>'; 
	    header("Content-Type: application/vnd.ms-excel;");
		header("Content-Disposition: attachment;filename=userinfo.xls");
		echo $data;
	}*/

	public function uploadQRcode() {

		$qrcode = $this->loadlib('mqrcode', 'qrcode');
		$uploadImg = $this->loadlib('qiniu', 'qiniu');

		$filename = 'qrcode' . rand(1, 999) . '.png';
		$logoPath = 'http://m200.yeapoo.us/style/t34/images/smile.png';
		$data = 'http://www.baidu.com';

		$qrcode->png($data, PHPTMP_PATH . $filename, $logoPath);

		$ret = $uploadImg->upload(randomkey('SIMPLE'), PHPTMP_PATH . $filename);

		if (! empty($ret['key'])) {

			var_dump($ret);
		}

		unlink(PHPTMP_PATH . $filename);
	}

	public function produceQRcode() {
		$qrcode = $this->loadlib('mqrcode', 'qrcode');
		$filename = 'qrcode_test.png';
		#$filename = 'share.jpg';
		$logoPath = '/sync/smile.png'; 

		$data = 'http://www.baidu.com';

		$qrcode->png($data, PHPTMP_PATH . $filename, $logoPath);

		echo "come over";
	}

	public function validate() {

		$source = 'Hello, world !';

		//$des = authcode($source, 'ENCODE', '123');
		$des = cryptare($source, '123', 'blowfish', 1);
		//echo $des . "<br>";

		//$src = authcode($des, 'DECODE', '123');
		$src = cryptare($des, '123', 'blowfish', 0);

		echo $src . "<br>";

	}

}

?>
